package com.softer.chengxin.common.domin;


import org.apache.commons.lang3.StringUtils;

/**
 * 界面消息
 *
 * @author Gong Zhiyang
 */
public class MessageBean {

    /**
     * 操作结果
     */
    private Boolean success;
    /**
     * 提示消息
     */
    private String message;
    /**
     * 对象实体
     */
    private Object bean;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    public Object getBean() {
        return bean;
    }

    public void setBean(Object bean) {
        this.bean = bean;
    }

    @Override
    public String toString() {
        return "MessageBean [success=" + success + ", message=" + message + "]";
    }

    public MessageBean() {
        super();
        this.success = success;
        this.message = message;
    }

    public MessageBean(Boolean success, String message, Object bean) {
        super();
        this.success = success;
        this.message = message;
        this.bean = bean;
    }

    public MessageBean(boolean success, String message) {
        super();
        this.success = success;
        this.message = message;
    }

    public MessageBean(Exception ex) {
        super();
        this.success = false;
        this.message = StringUtils.defaultIfBlank(ex.getMessage(), "程序异常");
    }

    public static MessageBean success() {
        MessageBean messageBean = new MessageBean();
        messageBean.setSuccess(true);
        messageBean.setMessage(Common.OPERATE_SUCCESS);
        return messageBean;
    }

    public static MessageBean success(String msg) {
        MessageBean messageBean = new MessageBean();
        messageBean.setSuccess(true);
        messageBean.setMessage(msg);
        return messageBean;
    }

    public static MessageBean fail(String msg) {
        MessageBean messageBean = new MessageBean();
        messageBean.setSuccess(false);
        messageBean.setMessage(msg);
        return messageBean;
    }

    public static MessageBean fail() {
        return fail("操作失败");
    }

}
